<template>
    <div class="outer">
        <div class="y1">
            <div class="list" v-for="item in list" :key="item.id" @click="goPage('/association/youping', item.id)">
                <img :src="item.avatar" alt="">
                <div class="list_t2">
                    <div class="name vip">
                        <span class="line2 ">{{ item.user_nickname }}</span>
                        <img src="@/assets/img/vip.svg" alt="">
                    </div>
                    <span class="line1 sign">{{ item.signature }}</span>
                </div>
            </div>
            <el-empty style="margin:0 auto" description="没有内容了" v-if="list.length == 0"></el-empty>

        </div>

    </div>
</template>
<script>
export default {

    data() {
        return {
            list: [],
            dialogVisible: false,
            form: { type: '' },
            pageNum: 1,
            totalPage: 1,
            loading: false,
            user_id: 0,

        }
    },
    computed: {
        keyword() {
            return this.$route.query.keyword
        },
    },
    watch: {
        keyword(n) {
            this.pageNum = 1
            this.list = []
            this.getList()
        },
    },
    mounted() {
        let uid = this.$route.query.id
        if (uid) {
            this.user_id = uid
            this.pageNum = 1
        }
        this.getList()

        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },

    methods: {
        goPage(url, id) {
            console.log(id);
            if (id) {
                this.$router.push({
                    path: url,
                    query: {
                        id
                    }
                })
            }
        },
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
                user_id: this.user_id,
                keyword: this.keyword

            }
            this.$api.getFans(params).then(res => {
                if (res.data.code == 1) {

                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },

        load() {
            console.log("处理触底");
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        onsubmit() {
            console.log(this.form);

        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.outer {
    display: flex;
    align-items: flex-start;
    padding-bottom: 20px;

    .y1 {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
    }

    .list {
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        width: calc(33% - 12.5px);

        &:nth-child(3n) {
            margin-left: 25px;
        }

        &:nth-child(3n-1) {
            margin-left: 25px;
        }

        cursor: pointer;
        display: flex;
        align-items: center;
        border: 1px solid #C3DCFB;
        margin-bottom: 1.04rem;
        padding: 1.04rem 1.6rem 0.94rem 0.99rem;

        >img {
            width: 4.17rem;
            height: 4.17rem;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .list_t {
            flex: 1;

            margin-left: 0.99rem;
            display: flex;
            justify-content: space-between;
            flex-direction: column;
            height: 100%;
            width: 14.27rem;

            >span {
                font-weight: 400;
                font-size: 1.15rem;
                color: #000000;
            }

            >div {
                display: flex;
                align-items: center;
                justify-content: space-between;

                >span {
                    font-weight: 400;
                    font-size: 1.04rem;
                    color: #999999;
                }

                >div {
                    font-weight: 400;
                    font-size: 0.94rem;
                    color: #999999;

                    img {
                        width: 1.2rem;
                        height: 0.83rem;
                        margin-right: 0.3rem;
                    }
                }
            }
        }

        .list_t2 {
            margin-left: 0.99rem;
            display: flex;
            justify-content: space-between;
            flex-direction: column;
            height: 100%;
            width: 14.27rem;

            .name {
                display: flex;
                align-items: center;
                font-weight: 400;
                font-size: 1.15rem;
                color: #333333;

                img {
                    width: 1.25rem;
                    height: 1.25rem;
                    margin-left: 0.7rem;
                    flex-shrink: 0;
                }
            }

            .vip {
                color: #1068E7;
            }

            .sign {
                width: 100%;
                font-weight: 400;
                font-size: 1.04rem;
                color: #666666;
                margin-bottom: 10px;
            }

            .hot {
                display: flex;
                align-items: center;
                margin-top: 0.5rem;

                div {
                    display: flex;
                    align-items: center;
                    font-weight: 400;
                    font-size: 0.94rem;
                    color: #999999;
                    margin-right: 1.6rem;

                    img {

                        width: 0.99rem;
                        height: 0.99rem;
                    }

                    &:nth-child(2) {
                        img {
                            width: 0.99rem;
                            height: 0.99rem;
                        }
                    }
                }
            }
        }

    }
}
@media screen and (max-width:768px) {
    .y1 {
        padding: 0 10px;
        .list {
            margin: 0 0 10px !important;
            padding: 10px;
            width: 100%;
            height: 100px;
            margin-bottom: 10px;

            >img {
                width: 70px;
                height: 70px;
            }

            .list_t2 {
                margin-left: 15px;
                flex: 1;

                .sign {
                    font-size: 15px;
                    line-height: normal;
                }

                .name {
                    font-size: 15px;

                    img {
                        width: 10px;
                        height: 10px;
                        margin-left: 8px;
                    }
                }

                .hot {
                    div {
                        font-size: 13px;

                        &:nth-child(2) {
                            img {
                                width: 15px;
                                height: 15px;
                                margin-right: 5px;
                            }
                        }

                        img {
                            width: 15px;
                            height: 15px;
                            margin-right: 5px;
                        }
                    }
                }
            }
        }
    }
}
</style>